<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input id="d1" type="text">
<input id="d2" type="text">
<input type="button" value="平方" onclick="f()">
<input type="button" value="求和" onclick="f1()">
<div>结果:</div>
<script>
    let i = document.querySelector("#d1");
    let i1 = document.querySelector("#d2");
    let d = document.querySelector("div");

    function f1() {
        d.innerText = "结果:" + (parseFloat(i1.value) + parseFloat(i.value));
    }

    function f() {
        if (isNaN(i.value)) {
            d.innerText = "输入错误!";
            return;
        }
        d.innerText = "结果:" + i.value * i.value;
    }

</script>
</body>
</html>